//
//  JgAdsSplashCustomEvent.m
//  AnyThinkSDKDemo
//
//  Created by Erik on 2021/12/6.
//  Copyright © 2021 抽筋的灯. All rights reserved.
//

#import "JgAdsSplashCustomEvent.h"

@interface JgAdsSplashCustomEvent()



@end

@implementation JgAdsSplashCustomEvent
- (void)loadAdWithPosId:(NSString *)posId bottomView:(UIView *)bottomView{
    self.splashAdContainer = [[JgAdsSplashAdContainer alloc] initPosId:posId delegate:self];
    [self.splashAdContainer loadAdWithBottomView:bottomView];
}
- (void)showAdWithWindow:(UIWindow *)window withBottomView:(UIView *)bottomView{
    [self.splashAdContainer showAdInWindow:window withBottomView:bottomView];
}
// MARK: - Method
- (void)loadAndShowPosId:(NSString *)posId window:(UIWindow *)window withBottomView:(nullable UIView *)bottomView{
    self.splashAdContainer = [[JgAdsSplashAdContainer alloc] initPosId:posId delegate:self];
    [self.splashAdContainer loadAndShowInWindow:window withBottomView:bottomView];
}


// MARK: - JgAdsSplash Delegate

/**
 *  开屏广告请求成功
 */
- (void)jgadsSplashAdSuccessLoad:(JgAdsSplashAd *)splashAd {
    
}

/**
 *  开屏广告素材渲染成功
 */
- (void)jgadsSplashAdDidLoad:(JgAdsSplashAd *)splashAd {
    if([[NSDate date] timeIntervalSinceDate:_expireDate] > 0){
//        NSError *error = [NSError errorWithDomain:ATADLoadingErrorDomain code:ATADLoadingErrorCodeADOfferLoadingFailed userInfo:@{NSLocalizedDescriptionKey:@"AT has failed to load splash.", NSLocalizedFailureReasonErrorKey:@"It took too long for jgads to load splash."}];
                [self trackSplashAdLoadFailed:nil];
    }else{
            [self trackSplashAdLoaded:self.splashAdContainer];
    }
}

/**
 *  开屏广告请求失败
 */
- (void)jgadsSplashAdFailLoad:(JgAdsSplashAd *)splashAd withError:(NSError *)error {
    [_splashAdContainer close];
    [self trackSplashAdLoadFailed:error];
}
/**
 *  开屏广告渲染失败
 */
- (void)jgadsSplashAdRenderFaild:(JgAdsSplashAd *)splashAd withError:(NSError *)error {
    [_splashAdContainer close];
    [self trackSplashAdLoadFailed:error];
}
/**
 *  开屏广告展示成功
 */
- (void)jgadsSplashAdDidPresent:(JgAdsSplashAd *)splashAd{
}
/**
 *  开屏广告曝光回调
 */
- (void)jgadsSplashAdExposured:(JgAdsSplashAd *)splashAd {
    [self trackSplashAdShow];
}

/**
 *  开屏广告点击回调
 */
- (void)jgadsSplashAdClicked:(JgAdsSplashAd *)splashAd {
    [self trackClick];
}

/**
 *  开屏广告关闭回调
 */
- (void)jgadsSplashAdClosed:(JgAdsSplashAd *)splashAd {
    [_splashAdContainer close];
    [self trackSplashAdClosed:nil];
}

- (void)jgadsSplashAdCloseLandingPage:(JgAdsSplashAd *)splashAd{
    [_splashAdContainer close];
    [self trackSplashAdClosed:nil];
}

- (NSString *)networkUnitId {
    return self.serverInfo[@"slot_id"];
}

@end
